package com.satis.compose.get.widget

import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.material.BottomNavigation
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color

/**
 * @author sunshaobei on 2023/4/2
 */
@Composable
fun GetBottomBar(
    modifier: Modifier = Modifier.navigationBarsPadding(),
    backgroundColor: Color = Color.White,
    selectedItem: Int,
    selectedContentColor: Color = Color.White,
    unselectedContentColor: Color = Color.Gray,
    vararg items: GetBottomBarItem,
    itemClick: (Int) -> Unit
) {
    BottomNavigation(
        backgroundColor = backgroundColor, modifier = modifier
    ) {
        items.forEachIndexed { index, getBottomBarItem ->
            BottomNavigationItem(selected = selectedItem == index,
                onClick = {
                    itemClick.invoke(index)
                },
                icon = {
                    Icon(imageVector = Icons.Filled.Home, contentDescription = null)
                },
                selectedContentColor = selectedContentColor,
                unselectedContentColor = unselectedContentColor,
                label = {
                    Text(text = getBottomBarItem.title)
                })
        }
    }
}

data class GetBottomBarItem(val title: String, val iconId: Int, val body: @Composable () -> Unit)